package cn.lang.auth.common.utils.ret;

/**
* @title: CodeMsg
* @description: 异常封装
* @author: Lang 1102076808@qq.com
* @date: 2020/6/18 23:41
*/
public class CodeMsg {

    private int code;
    private String msg;
    public int getCode() {
        return code;
    }
    public void setCode(int code) {
        this.code = code;
    }
    public String getMsg() {
        return msg;
    }
    public void setMsg(String msg) {
        this.msg = msg;
    }

    public static CodeMsg SUCCESS = new CodeMsg(200,"SUCCESS");
    /**服务端异常*/
    public static CodeMsg SERVER_SYS_ERROR = new CodeMsg(500,"系统异常：%s");
    public static CodeMsg SERVER_LOGIN_ERROR = new CodeMsg(501,"登录异常：%s");
    public static CodeMsg SERVER_AUTH_ERROR = new CodeMsg(502,"认证异常：%s");
    public static CodeMsg SERVER_ERROR = new CodeMsg(505,"%s");
    public static CodeMsg BIND_ERROR = new CodeMsg(101,"参数校验异常：%s");
    public static CodeMsg SESSION_ERROR = new CodeMsg(102,"没有SESSION！");
    public static CodeMsg REQUEST_ERROR = new CodeMsg(103,"非法请求！");
    public static CodeMsg REQUEST_OVER_LIMIT = new CodeMsg(104,"请求次数过多！");

    private CodeMsg( ) {
    }
    private CodeMsg( int code,String msg ) {
        this.code = code;
        this.msg = msg;
    }
    /**
     * @Description:不定参的构造函数
     * @author: Lang
     * @Date: 2020/6/18 23:40
     */
    public CodeMsg fillArgs(Object... args) {
        int code = this.code;
        String message = String.format(this.msg, args);
        return new CodeMsg(code, message);
    }
    @Override
    public String toString() {
        return "CodeMsg [code=" + code + ", msg=" + msg + "]";
    }
}
